package com.oneday.nuo.base.controller;


import cn.hutool.core.lang.tree.Tree;
import com.oneday.nuo.base.dto.NuoDeptDTO;
import com.oneday.nuo.base.dto.NuoMenuDTO;
import com.oneday.nuo.base.entity.NuoDeptEntity;
import com.oneday.nuo.base.response.NuoResult;
import com.oneday.nuo.base.service.NuoDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 部门表(NuoDept)表控制层
 *
 * @author liushuai
 * @since 2021-03-13 23:37:00
 */
@RestController
@RequestMapping("api/dept")
@Api(tags="NuoDeptController")
@ApiModel(value = "",description = "部门表")
public class NuoDeptController {
    @Autowired
    private NuoDeptService nuoDeptService;

    @ApiOperation(value = "保存部门" ,  notes="保存部门")
    @PreAuthorize("hasAnyAuthority('sys:dept:viewList')")
    @PostMapping("saveDept")
    public NuoResult saveDept(@RequestBody NuoDeptDTO nuoDeptDTO){
        nuoDeptService.saveDept(nuoDeptDTO);
        return NuoResult.buildResponseSave();
    }

    @ApiOperation(value = "根据id查询部门" ,  notes="根据id查询部门")
    @GetMapping("queryDeptById")
    public NuoResult queryDeptById(@RequestParam("id") String id){
        NuoDeptEntity entity =  nuoDeptService.queryDeptById(id);
        return NuoResult.buildResponseQuery(entity);
    }

    @ApiOperation(value = "根据id删除部门" ,  notes="根据id删除部门")
    @GetMapping("deleteDeptById")
    public NuoResult deleteDeptById(@RequestParam("id") String id){
        nuoDeptService.deleteDeptById(id);
        return NuoResult.buildResponseDelete();
    }
    @ApiOperation(value = "查询所有部门" ,  notes="查询所有部门")
    @GetMapping("queryAllDept")
    @PreAuthorize("hasAnyAuthority('sys:dept:viewList')")
    public NuoResult queryAllDept(@RequestParam(required = false) Map<String ,Object> map){
        List<Tree<String>> deptAll =  nuoDeptService.queryAllDept(map);
        return NuoResult.buildResponseQuery(deptAll);
    }



}